package com.example.yeujian5.yuejian5.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.yeujian5.yuejian5.Listenner.UserListener;
import com.example.yeujian5.yuejian5.R;
import com.example.yeujian5.yuejian5.bean.UserBean;
import com.example.yeujian5.yuejian5.model.UserModel;

public class RegistActivity extends AppCompatActivity implements View.OnClickListener, UserListener {

    private Button button_reg, button_cancle;
    private EditText et_pass,et_tele,et_username;


    String phone;
    String pwd;
    String name;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_regist);

        initViews();


    }

    public void initViews(){
        button_reg=(Button)findViewById(R.id.reg);
        button_cancle=(Button)findViewById(R.id.cancle);
        et_pass=(EditText)findViewById(R.id.pass);
        et_tele=(EditText)findViewById(R.id.telephone);
        et_username=(EditText)findViewById(R.id.username);

        button_reg.setOnClickListener(this);
        button_cancle.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.reg:
                name = et_username.getText().toString();
                phone = et_tele.getText().toString();
                pwd = et_pass.getText().toString();

                UserModel usermodel = new UserModel();
                usermodel.getRegister(name,phone,pwd, this);
                break;
            case R.id.cancle:
                finish();
        }
    }

    //这个方法是在Model中调用的
    @Override
    public void onResponse(UserBean userBean) {
        Toast.makeText(this, "注册成功!", Toast.LENGTH_SHORT).show();
    }


    @Override
    public void onFail(String msg) {
        Toast.makeText(this, "" + msg, Toast.LENGTH_SHORT).show();
    }
}
